/**
 * 
 */
package jmai.evaluator;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Jean-Pierre
 *
 */
public class Helper {

	public static Boolean validate(String input) {
		char[] tmp = input.toCharArray();
		
		for(int i=0; i< tmp.length; i++) {
			if(tmp[i] != 'a' && tmp[i] != 'b' && tmp[i] != 'c')
				return false;
		}
		
		//System.out.println("jmai: input string is " + input);
		
		return true;
	}
	
	public static ArrayList<String> input(String src) {
		
		ArrayList<String> dst = null;
		Scanner sc = null;
		
		try {
			sc = new Scanner(new File(src));
			dst = new ArrayList<String>();
			
			while(sc.hasNextLine()) {
				Boolean isValid = true;
				char[] tmp = sc.nextLine().toCharArray();
				
				//System.out.println("Read in: " + (new String(tmp)));
				
				for(int i=0; i<tmp.length; i++) {
					switch(tmp[i]) {
						case 'a': break;
						case 'b': break;
						case 'c': break;
						default: isValid = false;
							break;
					}
				}
				
				if(isValid) {
					dst.add(new String(tmp));
				} else {
					System.out.println("jmai: input line invalid");
					System.out.println("jmai: ignoring " + new String(tmp));
				}
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			
			System.out.println("jmai: input file not found");
			System.exit(0);
			//e.printStackTrace();
		}
		
		return dst;
	}
}
